package gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import model.basics.Instructor;
import org.jdesktop.application.Application;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModifyWind extends javax.swing.JFrame {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Instructor instructor;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JButton cancelButton;
	private JTextField mailField;
	private JTextField phoneField;
	private JTextField idField;
	private JButton okButton;
	private JLabel jLabel1;
	private JTextField nameField;
	private JTextPane mail;
	private JTextPane name;
	private JTextPane dni;
	private JTextPane phone;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ModifyWind inst = new ModifyWind(new Instructor());
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public ModifyWind(Instructor i, JTextPane name, JTextPane mail, JTextPane dni, JTextPane phone) {
		super();
		this.instructor = i;
		this.name = name;
		this.mail = mail;
		this.dni = dni;
		this.phone = phone;
		this.setVisible(true);
		initGUI();
	}
	
	public ModifyWind(Instructor instructor2) {
		// TODO Auto-generated constructor stub
		super();
		this.instructor = instructor2;
		this.setVisible(true);
		initGUI();
	}

	private void initGUI() {
		this.setTitle("Modify "+instructor.getName());
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setLocation(new java.awt.Point(60, 60));
			{
				nameField = new JTextField();
				getContentPane().add(nameField);
				nameField.setBounds(192, 25, 137, 21);
				nameField.setText(instructor.getName());
				
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setBounds(35, 28, 90, 14);
				jLabel1.setName("jLabel1");
			}
			{
				okButton = new JButton();
				getContentPane().add(okButton);
				okButton.setBounds(76, 234, 84, 21);
				okButton.setName("okButton");
				okButton.addActionListener(new closeW(this));
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setBounds(35, 83, 130, 14);
				jLabel2.setName("jLabel2");
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setBounds(35, 131, 130, 14);
				jLabel3.setName("jLabel3");
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setBounds(35, 182, 85, 14);
				jLabel4.setName("jLabel4");
			}
			{
				idField = new JTextField();
				getContentPane().add(idField);
				idField.setBounds(192, 76, 137, 21);
				idField.setText((((Integer)(instructor.getDNI())).toString()));
			}
			{
				phoneField = new JTextField();
				getContentPane().add(phoneField);
				phoneField.setBounds(192, 124, 137, 21);
				phoneField.setText(((Integer)(instructor.getPhoneNumber())).toString());
			}
			{
				mailField = new JTextField();
				getContentPane().add(mailField);
				mailField.setBounds(192, 175, 137, 21);
				mailField.setText(instructor.getMail());
			}
			{
				cancelButton = new JButton();
				getContentPane().add(cancelButton);
				cancelButton.setBounds(231, 234, 84, 21);
				cancelButton.setName("cancelButton");
				cancelButton.addActionListener(new Cancel(this));
			}
			pack();
			setSize(400, 300);
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(getContentPane());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public class closeW implements ActionListener{
		private JFrame j;
		
		public closeW(JFrame j){
			this.j = j;
		}
		
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			instructor.setName(nameField.getText());
			instructor.setMail(mailField.getText());
			instructor.setDni(Integer.parseInt((idField.getText())));
			instructor.setPhone(Integer.parseInt(phoneField.getText()));
			//name.setText(nameField.getText());
			//mail.setText(mailField.getText());
			//dni.setText((idField.getText()));
			//phone.setText((phoneField.getText()));
			j.dispose();
			
		}
		
	}
	
	public class Cancel implements ActionListener{
		private JFrame frame;
		public Cancel(JFrame frame){
			this.frame = frame;
		}
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			this.frame.dispose();
		}
		
	}
	
}
